package com.huawei.appmarket.framework.titleframe.title;

import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import com.huawei.android.app.ActionBarEx;
import com.huawei.appgallery.forum.posts.api.PostProfiles;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.ShareBaseTitleBean;
import com.huawei.appmarket.framework.MainActivityBase;
import huawei.widget.HwTextView;
import o.azb;
import o.azc;
import o.bzh;
import o.bzj;
import o.cjf;
import o.dga;
import o.dgc;
import o.dhl;
import o.dje;
import o.Logger;
import o.dof;
import o.dzn;
import o.dzn.e;
import o.evf;
import o.evx;
import o.ewm;
import o.ewm.c;
import o.ewm.d;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;

public abstract class WiseDistBaseTitle extends cjf {
    protected View ʻ;
    protected View ʼ;
    protected View ʽ;
    private LinearLayout ˊॱ;
    protected View ˏ;
    private boolean ˏॱ = false;
    private LinearLayout ͺ;
    private LinearLayout ॱˊ;
    protected HwTextView ॱॱ;
    protected LinearLayout ᐝ;

    protected abstract boolean ˊॱ();

    protected abstract boolean ˏॱ();

    protected abstract boolean ͺ();

    protected abstract boolean ॱˊ();

    public WiseDistBaseTitle(Activity activity, BaseTitleBean baseTitleBean) {
        super(activity, baseTitleBean);
    }

    public View ʽ() {
        ActionBar actionBar = this.ˋ.getActionBar();
        this.ˏॱ = ॱ(actionBar);
        this.ˊॱ = (LinearLayout) this.ˊ.inflate(h.ॱﹶ, null);
        azb.ˏ(this.ˊॱ);
        int ʼ = ʼ();
        int ˋॱ = ˋॱ();
        if (ʼ > 0) {
            evf.ॱ(this.ˊॱ, ʼ);
        }
        ˋ(ʼ, ˋॱ);
        this.ˏ = this.ˊॱ.findViewById(j.ˋᐠ);
        this.ˏ.setOnClickListener(new evx(this) {
            final /* synthetic */ WiseDistBaseTitle ˋ;

            {
                this.ˋ = r1;
            }

            public void ˋ(View view) {
                this.ˋ.ˋ.onBackPressed();
            }
        });
        this.ˏ.setContentDescription(this.ˋ.getResources().getString(n.ॱˌ));
        this.ᐝ = (LinearLayout) this.ˊॱ.findViewById(j.ˋᑊ);
        this.ʼ = this.ˊॱ.findViewById(j.ˍꜟ);
        this.ʼ.setContentDescription(this.ˋ.getResources().getString(n.ˊᵔ));
        this.ʻ = this.ˊॱ.findViewById(j.ˍꓸ);
        this.ʻ.setContentDescription(this.ˋ.getResources().getString(n.ˊי));
        this.ʽ = this.ˊॱ.findViewById(j.ˈˈ);
        this.ॱˊ = (LinearLayout) this.ˊॱ.findViewById(j.ˌـ);
        this.ͺ = (LinearLayout) this.ˊॱ.findViewById(j.ˌˍ);
        View view = this.ˏ;
        boolean z = this.ˏॱ;
        boolean z2 = !ʾ() && ॱˊ();
        ˎ(view, z, z2);
        ˎ(actionBar);
        if (ʿ()) {
            this.ॱˊ.setVisibility(8);
            this.ʻ.setVisibility(8);
            this.ʼ.setVisibility(8);
            this.ͺ.setVisibility(8);
            ʻॱ();
        } else {
            ॱ(false);
        }
        try {
            this.ᐝ.addView(ॱˎ());
        } catch (Throwable e) {
            Logger.ˋ("WiseDistBaseTitle", "can not create content view", e);
        }
        ॱ(ˎ());
        if (this.ˏॱ) {
            return this.ˊॱ;
        }
        actionBar.show();
        this.ˏ.setVisibility(8);
        if (ॱˊ()) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        } else {
            actionBar.setDisplayHomeAsUpEnabled(false);
        }
        if (this.ॱॱ != null) {
            actionBar.setDisplayShowTitleEnabled(true);
            this.ᐝ.setVisibility(8);
        } else {
            actionBar.setDisplayShowTitleEnabled(false);
            this.ᐝ.setVisibility(0);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setCustomView(this.ˊॱ, new LayoutParams(-1, -2));
        }
        return null;
    }

    private void ʻॱ() {
        if (this.ˋ instanceof dje) {
            bzh ˊˊ = ((dje) this.ˋ).ˊˊ();
            if (ˊˊ != null) {
                ॱ(ˊˊ);
                ॱ(true);
                return;
            }
            dzn.ॱ(((dje) this.ˋ).ˋˊ(), new e(this) {
                final /* synthetic */ WiseDistBaseTitle ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˋ(PostProfiles postProfiles) {
                    if (postProfiles != null) {
                        bzh o_bzh = new bzh();
                        o_bzh.ˎ(postProfiles);
                        if (this.ˎ.ˋ instanceof dje) {
                            ((dje) this.ˎ.ˋ).ˋ(o_bzh);
                        }
                        this.ˎ.ॱ(o_bzh);
                        this.ˎ.ॱ(true);
                        return;
                    }
                    this.ˎ.ॱ(false);
                }
            });
        }
    }

    private void ॱ(bzh o_bzh) {
        this.ॱˊ.removeAllViews();
        this.ॱˊ.setVisibility(0);
        ((bzj) fho.ˏ().ˋ("Posts").ॱ(bzj.class)).ॱ(this.ॱˊ, o_bzh);
        if (this.ॱॱ != null) {
            ViewGroup.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.ॱॱ.getLayoutParams();
            if (layoutParams == null) {
                layoutParams = new LinearLayout.LayoutParams(-2, -2);
            }
            layoutParams.setMarginEnd(this.ˋ.getResources().getDimensionPixelSize(d.ᐝˊ));
            this.ॱॱ.setLayoutParams(layoutParams);
        }
    }

    protected void ॱ(boolean z) {
        boolean z2 = true;
        ActionBar actionBar = this.ˋ.getActionBar();
        this.ˏॱ = ॱ(actionBar);
        if (z) {
            ˎ(this.ॱˊ, this.ˏॱ, true);
            if (ˏॱ() && ͺ()) {
                ˎ(this.ʻ, this.ˏॱ, false);
                ˎ(this.ʼ, this.ˏॱ, false);
                ˎ(this.ͺ, this.ˏॱ, true);
                this.ͺ.setOnClickListener(new evx(this) {
                    final /* synthetic */ WiseDistBaseTitle ˊ;

                    {
                        this.ˊ = r1;
                    }

                    public void ˋ(View view) {
                        this.ˊ.ॱᐝ();
                    }
                });
                z2 = false;
            }
        } else {
            this.ͺ.setVisibility(8);
            this.ॱˊ.setVisibility(8);
        }
        if (z2) {
            ˎ(this.ʻ, this.ˏॱ, ˏॱ());
            ˎ(this.ʼ, this.ˏॱ, ͺ());
            ᐝॱ();
            ॱˋ();
        }
        z2 = ˏ(this.ˏॱ);
        if (ˊ(this.ˏॱ) || z2) {
            this.ʽ.setVisibility(0);
            ActionBarEx.setEndIcon(actionBar, false, null, null);
        } else {
            this.ʽ.setVisibility(8);
        }
        if (ˏॱ() || ͺ()) {
            this.ʽ.setVisibility(0);
        }
    }

    private void ॱᐝ() {
        PopupMenu popupMenu = new PopupMenu(this.ˋ, this.ͺ);
        ˊ(popupMenu.getMenu().add(this.ˋ.getResources().getString(n.ʳ)));
        ˎ(popupMenu.getMenu().add(this.ˋ.getResources().getString(n.ˋי)));
        popupMenu.show();
    }

    private void ॱˋ() {
        this.ʻ.setOnClickListener(new evx(this) {
            final /* synthetic */ WiseDistBaseTitle ˏ;

            {
                this.ˏ = r1;
            }

            public void ˋ(View view) {
                if (this.ˏ.ॱ == null) {
                    Logger.e("WiseDistBaseTitle", "iTitleDataChangedListener is null, illegal");
                } else {
                    this.ˏ.ॱ.ʼʽ();
                }
            }
        });
    }

    private void ᐝॱ() {
        this.ʼ.setOnClickListener(new evx(this) {
            final /* synthetic */ WiseDistBaseTitle ˋ;

            {
                this.ˋ = r1;
            }

            public void ˋ(View view) {
                if (this.ˋ.ॱ == null) {
                    Logger.e("WiseDistBaseTitle", "iTitleDataChangedListener is null, illegal");
                } else if (this.ˋ.ˎ instanceof ShareBaseTitleBean) {
                    this.ˋ.ॱ.ˋ(((ShareBaseTitleBean) this.ˋ.ˎ).ˎ());
                }
            }
        });
    }

    private void ˎ(ActionBar actionBar) {
        if (!ˊॱ()) {
            if (actionBar != null) {
                actionBar.setTitle("");
            }
            if (this.ॱॱ != null) {
                this.ॱॱ.setVisibility(8);
            }
        }
    }

    private boolean ˏ(boolean z) {
        if (!ͺ() || z || !(this.ˋ instanceof dga)) {
            return false;
        }
        Menu ʽॱ = ((dga) this.ˋ).ʽॱ();
        if (ʽॱ != null) {
            ˋ(ʽॱ);
        } else {
            ((dga) this.ˋ).ˊ(new dgc(this) {
                final /* synthetic */ WiseDistBaseTitle ˏ;

                {
                    this.ˏ = r1;
                }

                public void ˏ(@NonNull Menu menu) {
                    this.ˏ.ˋ(menu);
                }
            });
        }
        return true;
    }

    protected MenuItem ˋ(Menu menu) {
        MenuItem findItem = menu.findItem(j.ॱᶡ);
        if (findItem == null) {
            findItem = menu.add(0, j.ॱᶡ, 0, null);
            findItem.setIcon(ʽॱ());
            findItem.setContentDescription(this.ˋ.getResources().getString(n.ˊᵔ));
        }
        findItem.setShowAsAction(2);
        findItem.setVisible(true);
        ˊ(findItem);
        return findItem;
    }

    private void ˊ(MenuItem menuItem) {
        menuItem.setOnMenuItemClickListener(new dhl(this) {
            final /* synthetic */ WiseDistBaseTitle ˋ;

            {
                this.ˋ = r1;
            }

            public boolean ˎ(MenuItem menuItem) {
                if (this.ˋ.ॱ == null || !(this.ˋ.ˎ instanceof ShareBaseTitleBean)) {
                    Logger.e("WiseDistBaseTitle", "listener:" + this.ˋ.ॱ + ",titleBean:" + this.ˋ.ˎ);
                } else {
                    this.ˋ.ॱ.ˋ(((ShareBaseTitleBean) this.ˋ.ˎ).ˎ());
                }
                return true;
            }
        });
    }

    private int ʽॱ() {
        int i = ewm.e.ˎ;
        if (azc.ˎ().ॱ() < 9 || azc.ˋ(this.ˋ) != 0) {
            return i;
        }
        return ewm.e.ʻˊ;
    }

    private boolean ˊ(boolean z) {
        if (!ˏॱ() || z || !(this.ˋ instanceof dga)) {
            return false;
        }
        Menu ʽॱ = ((dga) this.ˋ).ʽॱ();
        if (ʽॱ != null) {
            ˎ(ʽॱ);
        } else {
            ((dga) this.ˋ).ˊ(new dgc(this) {
                final /* synthetic */ WiseDistBaseTitle ˏ;

                {
                    this.ˏ = r1;
                }

                public void ˏ(@NonNull Menu menu) {
                    this.ˏ.ˎ(menu);
                }
            });
        }
        return true;
    }

    protected MenuItem ˎ(Menu menu) {
        MenuItem findItem = menu.findItem(j.ॱᶦ);
        if (findItem == null) {
            findItem = menu.add(0, j.ॱᶦ, 0, null);
            findItem.setIcon(ewm.e.ﹳ);
            findItem.setContentDescription(this.ˋ.getResources().getString(n.ˊי));
        }
        findItem.setShowAsAction(2);
        findItem.setVisible(true);
        ˎ(findItem);
        return findItem;
    }

    private void ˎ(MenuItem menuItem) {
        menuItem.setOnMenuItemClickListener(new dhl(this) {
            final /* synthetic */ WiseDistBaseTitle ॱ;

            {
                this.ॱ = r1;
            }

            public boolean ˎ(MenuItem menuItem) {
                if (this.ॱ.ॱ != null) {
                    this.ॱ.ॱ.ʼʽ();
                } else {
                    Logger.e("WiseDistBaseTitle", "listener:" + this.ॱ.ॱ);
                }
                return true;
            }
        });
    }

    private boolean ॱ(ActionBar actionBar) {
        if (actionBar != null) {
            actionBar.hide();
        }
        return true;
    }

    private void ˎ(View view, boolean z, boolean z2) {
        if (z2) {
            if (z) {
                z2 = true;
            } else {
                z2 = false;
            }
        }
        if (z2) {
            view.setVisibility(0);
        } else {
            view.setVisibility(8);
        }
    }

    private boolean ʾ() {
        if (MainActivityBase.class.isAssignableFrom(this.ˋ.getClass())) {
            return true;
        }
        return false;
    }

    protected View ॱˎ() {
        this.ॱॱ = (HwTextView) LayoutInflater.from(this.ˋ).inflate(h.ˋˈ, null);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
        if ((this.ˏ == null || this.ˏ.getVisibility() == 8) && !ˏॱ() && !ͺ()) {
            layoutParams.setMarginStart(this.ˋ.getResources().getDimensionPixelSize(d.ᐝˊ));
            layoutParams.setMarginEnd(this.ˋ.getResources().getDimensionPixelSize(d.ᐝˊ));
        } else if ((this.ˏ == null || this.ˏ.getVisibility() == 8) && (ˏॱ() || ͺ())) {
            layoutParams.setMarginStart(this.ˋ.getResources().getDimensionPixelSize(d.ᐝˊ));
        } else if (!(this.ˏ == null || this.ˏ.getVisibility() == 8 || ˏॱ() || ͺ()) || this.ॱˊ.getVisibility() == 0) {
            layoutParams.setMarginEnd(this.ˋ.getResources().getDimensionPixelSize(d.ᐝˊ));
        }
        ˊ(layoutParams);
        return this.ॱॱ;
    }

    private void ˊ(LinearLayout.LayoutParams layoutParams) {
        this.ॱॱ.setLayoutParams(layoutParams);
        CharSequence ˋ = this.ˎ.ˋ();
        if (TextUtils.isEmpty(ˋ)) {
            this.ॱॱ.setText("");
        } else {
            this.ॱॱ.setText(ˋ);
        }
    }

    public void ʻ() {
        ActionBar actionBar = this.ˋ.getActionBar();
        this.ˏॱ = ॱ(actionBar);
        CharSequence ˋ = this.ˎ.ˋ();
        if (this.ˏॱ) {
            if (actionBar != null) {
                actionBar.hide();
            }
            if (this.ॱॱ != null) {
                if (!ˊॱ() || TextUtils.isEmpty(ˋ)) {
                    this.ॱॱ.setText("");
                } else {
                    this.ॱॱ.setText(ˋ);
                }
            }
        }
        if (actionBar == null) {
            return;
        }
        if (ˊॱ()) {
            actionBar.setTitle(ˋ);
        } else {
            actionBar.setTitle("");
        }
    }

    protected int ʼ() {
        if (ʾ()) {
            return c.ॱˎ;
        }
        return c.ˎ;
    }

    @ColorRes
    protected int ˋॱ() {
        if (ʾ()) {
            return c.ˊ;
        }
        return c.ॱˎ;
    }

    private boolean ʿ() {
        if (!(this.ˋ instanceof dje)) {
            return false;
        }
        if (dof.ˋ(((dje) this.ˋ).ˋˊ())) {
            return false;
        }
        return true;
    }
}
